package define

import (
	"sync"
	"time"

	kadefine "kiwi/actor/define"
	katimer "kiwi/actor/timer"
	kawork "kiwi/actor/work"
	klog "kiwi/log"
)

type (
	OnActorReceiveFunc = func(ctx kadefine.Context) (continued bool)

	IActorOption interface {
		ActorID() string
		StartedWaitGroup() *sync.WaitGroup
		StoppedWaitGroup() *sync.WaitGroup
		MailBoxSize() int
		DeciderFunc() kadefine.DeciderFunc
		FromRoot() bool
	}

	IActorHandler interface {
		//OnStarted 派生类必须调用基类的OnStarted，否则初始化不完整
		OnStarted(ctx kadefine.Context)
		OnStopping(ctx kadefine.Context)
		OnStopped(ctx kadefine.Context)
		OnRestarting(ctx kadefine.Context)
		OnTerminate(ctx kadefine.Context, who *kadefine.PID, why kadefine.TerminatedReason)
		BeforeTriggerTimer(id katimer.ID, tag katimer.Tag, ctx kadefine.Context) (ok bool, err error)
		AfterTriggerTimer(err error, id katimer.ID, tag katimer.Tag, ctx kadefine.Context)
		OnReceive(ctx kadefine.Context)
	}

	IActor interface {
		IActorOption
		IActorHandler

		PID() *kadefine.PID

		Stop()
		Poison()

		Timer() *katimer.Manager

		Logger() klog.ILogger

		Post(work kawork.IPostWork) error
		Dispatch(timeout time.Duration, work kawork.IDispatchWork) error

		Send(message any)
		RequestFuture(message any, timeout time.Duration) *kadefine.Future
	}
)
